package org.lex.notepad.ui.action.edit;

import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JOptionPane;
import javax.swing.KeyStroke;

import org.lex.notepad.ui.NotepadEditor;
import org.lex.notepad.ui.action.BaseNotepadAction;

public class GotoLineAction extends BaseNotepadAction {
	public GotoLineAction() {
		super();
		this.setName("Goto Line...");
		this.setAcceleratorKey(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK, false));
	}

	public void actionPerformed(ActionEvent e) {
		Object val = JOptionPane.showInputDialog(notepad.getRootWindow(), "Line number:", "Goto Line", JOptionPane.QUESTION_MESSAGE, null, null, "1");
		if (null == val)
			return;
		try {
			int lineNo = Integer.parseInt(String.valueOf(val));
			NotepadEditor editor = notepad.getEditor();
			int pos = editor.getLineStartOffset(lineNo - 1);
			editor.setCaretPosition(pos);
		} catch (Exception E) {
		}
	}
}
